import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter_udid/flutter_udid.dart';
import 'package:device_info/device_info.dart';
import 'package:shared_preferences/shared_preferences.dart';

class BaseLibrariesUsed extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          icon: Icon(Icons.arrow_back),
          onPressed: () {
            Navigator.of(context).pop(1);
          },
        ),
        title: Text('基本依赖库的使用'),
      ),
      body: (Scrollbar(
        child: SingleChildScrollView(
          scrollDirection: Axis.vertical,
          reverse: true,
          padding: EdgeInsets.all(10.0),
          child: Column(
            children: <Widget>[
              Container(
                margin: EdgeInsets.symmetric(horizontal: 15.0, vertical: 20.0),
                width: double.infinity,
                child: RaisedButton(
                  textColor: Colors.white,
                  color: Colors.red,
                  child: Text('获取Udid'),
                  elevation: 5,
                  onPressed: () async {
                    String udid = await FlutterUdid.consistentUdid;
                    Fluttertoast.showToast(msg: "Udid=${udid}");
                  },
                ),
              ),
              Container(
                margin: EdgeInsets.symmetric(horizontal: 15.0, vertical: 20.0),
                width: double.infinity,
                child: RaisedButton(
                  textColor: Colors.white,
                  color: Colors.red,
                  child: Text('获取device_info'),
                  elevation: 5,
                  onPressed: () async {
                    DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
                    AndroidDeviceInfo androidInfo =
                        await deviceInfo.androidInfo;
                    print('BaseLibrariesUsed.build androidId=' +
                        androidInfo.androidId +
                        ' device=' +
                        androidInfo.device);
                    Fluttertoast.showToast(
                        msg: "androidInfo=${androidInfo.model}");

                    //IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
                    //Fluttertoast.showToast(msg: "iosInfo=${iosInfo.utsname.machine}");
                  },
                ),
              ),
              Container(
                  margin:
                      EdgeInsets.symmetric(horizontal: 15.0, vertical: 20.0),
                  width: double.infinity,
                  child: Text("shared_preferences 本地储存")),
              Container(
                margin: EdgeInsets.symmetric(horizontal: 15.0, vertical: 20.0),
                width: double.infinity,
                child: RaisedButton(
                  textColor: Colors.white,
                  color: Colors.red,
                  child: Text('保存'),
                  elevation: 5,
                  onPressed: () async {
                    SharedPreferences prefs =
                        await SharedPreferences.getInstance();
                    prefs.setString("userName", "ypk");
                    prefs.setInt("age", 100);
                    Fluttertoast.showToast(msg: "已保存");
                  },
                ),
              ),
              Container(
                margin: EdgeInsets.symmetric(horizontal: 15.0, vertical: 20.0),
                width: double.infinity,
                child: RaisedButton(
                  textColor: Colors.white,
                  color: Colors.red,
                  child: Text('获取'),
                  elevation: 5,
                  onPressed: () async {
                    SharedPreferences prefs =
                        await SharedPreferences.getInstance();
                    var userName = prefs.getString("userName");
                    var age = prefs.getInt("age");
                    print(
                        'BaseLibrariesUsed.build userName=$userName age=$age');
                  },
                ),
              ),
              Container(
                  margin:
                      EdgeInsets.symmetric(horizontal: 15.0, vertical: 20.0),
                  width: double.infinity,
                  child: Text("信息显示", key: Key('textId'))),

              CupertinoActivityIndicator(radius: 50),
            ],
          ),
        ),
      )),
    );
  }
}
